namespace CodeConsult.Nordic.nRF8001.ApplicationControlInterface.Commands.SystemCommands
{
    public class WriteDynamicDataCommand : AciCommandBase
    {
        public const byte OpCode = 0x08;

        public byte SequenceNumber { get; set; }
        public byte[] SetupData { get; set; }

        protected override void EncodeBuffer()
        {
            var length = (byte)SetupData.Length;
            Error = SetupData == null || length < 1 || length > 27;

            if (Error) return;

            EncodeBufferWithCommandHeader(OpCode, length + 1);
            EncodeHelper.SetByte(SequenceNumber);
            EncodeHelper.SetBytes(SetupData);
        }
    }
}
